home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #1 / Amiga Plus 1999 #1.iso / System-Boost / Sound / 8hzPPC / Changes.MagicSN < prev    next >
Text File  |  1998-08-09  |  10KB  |  410 lines

  1. Note: All changes are inside a
  2.  
  3. #ifdef __STORMC__
  4. ...
  5. #endif
  6.  
  7. and/or a
  8.  
  9. #ifndef __STORMC__
  10. ...
  11. #endif
  12.  
  13. Sources are not included, ask me or Mike Cheng or www.8hz.com (whom i both
  14. sent it) about them. Hope my changes will be integrated in future general
  15. versions of the 8Hz Encoder :)
  16.  
  17. I did not list the changes by Mike Cheng, see his changes-file about them...
  18. (like support for CDDA...). My version is based on Mike Cheng's sources...
  19.  
  20. bitstream.c:
  21. ------------
  22.  
  23. Replaced K&R Syntax Prototypes by "real" Prototypes, as StormC PPC does not
  24. like K&R Prototypes.
  25.  
  26. One example:
  27.  
  28. int refill_buffer(bs)
  29. bitstream_t *bs;   /* bit stream structure */
  30.  
  31. is changed to:
  32.  
  33. #ifndef __STORMC__
  34. int refill_buffer(bs)
  35. bitstream_t *bs;   /* bit stream structure */
  36. #else
  37. int refill_buffer(bitstream_t *bs)
  38. #endif
  39.  
  40. I recommend throwing out the K&R Prototypes for future versions to reduce
  41. the #ifndef's...
  42.  
  43. fft.c:
  44. ------
  45.  
  46. The same like in bitstream.c ...
  47.  
  48. ieeefloat.c:
  49. ------------
  50.  
  51. Changed
  52.  
  53. #include        <stdio.h>
  54. #include        <math.h>
  55. #include        "ieeefloat.h"
  56.  
  57. to:
  58.  
  59. #include        <stdio.h>
  60. #include        <math.h>
  61. #include        "ieeefloat.h"
  62. #ifdef __STORMC__
  63. #include <limits.h>
  64. #endif
  65.  
  66. (StormC needs this include)
  67.  
  68. l3subband.c:
  69. ------------
  70.  
  71. Changed
  72.  
  73. static off[2]    = {0,0};
  74.  
  75. (as this would be a syntax error for StormC)
  76.  
  77. to:
  78.  
  79. #ifdef __STORMC__
  80. static int off[2]={0,0};
  81. #else
  82. static off[2]    = {0,0};
  83. #endif
  84.  
  85. layer3.c:
  86. ---------
  87.  
  88. To reduce Contextswitches, i added the possibility to printf the status not every
  89. frame, but every 50th or 100th or such (Contextswitch are a special phenomen on
  90. the PowerPC Upgrades of the Amiga-Systems, and they consume time...):
  91.  
  92. Following the changed code:
  93.  
  94. #ifdef __STORMC__
  95. float fskip=100;
  96. #endif
  97.  
  98. static void update_status(int frames_processed)
  99. {
  100. #ifndef __STORMC__
  101.     printf("\015[Frame %6d of %6ld] (%2.2f%%)",
  102.             frames_processed,config.mpeg.total_frames,
  103.             (float)((float)frames_processed/config.mpeg.total_frames)*100);
  104.     fflush(stdout);
  105. #else
  106.     int fram=frames_processed;
  107.     fram=fram/fskip;
  108.     if (fram*fskip==frames_processed)
  109.     {
  110.      printf("\015[Frame %6d of %6ld] (%2.2f%%)",
  111.              frames_processed,config.mpeg.total_frames,
  112.              (float)((float)frames_processed/config.mpeg.total_frames)*100);
  113.      fflush(stdout);
  114.     }
  115. #endif
  116. }
  117.  
  118. main.c:
  119. -------
  120.  
  121. Changes are:
  122.  
  123. - concerning the changes in layer3.c a new parameter
  124. - there were some problems with parameter passing. Under certain circumstances
  125.   incorrect parameters (for example -b without actually giving a bitrate)
  126.   was not detected, i fixed this, but everything inside #ifdef __STORMC__
  127.   to not change the code of the encoder without permission...
  128.  
  129. Changed parts:
  130.  
  131. Behind:
  132.  
  133. #include "types.h"
  134. #include "error.h"
  135. #include "wave.h"
  136. #include "layer3.h"
  137.  
  138. i inserted:
  139.  
  140. #ifdef __STORMC__
  141. extern int fskip;
  142. #endif
  143.  
  144. print_usage looks now like:
  145.  
  146. static void print_usage()
  147. {
  148.     fprintf(stderr,"USAGE   :  8hz-mp3 [options] <infile> <outfile>\n");
  149.     fprintf(stderr,"OPTIONS : -h            this help message\n");
  150.     fprintf(stderr,"          -b <bitrate>  set the bitrate, default 128kbit\n");
  151.     fprintf(stderr,"          -c            set copyright flag, default off\n");
  152.     fprintf(stderr,"          -o            set original flag, default off\n");
  153. #ifdef MFCPCM
  154.     fprintf(stderr,"          -r            force raw PCM reading instead of wav\n");
  155.     fprintf(stderr,"          -f <Hz>       set frequency for PCM reading. Default: 44100\n");
  156.     fprintf(stderr,"          -x            pcm is bigEndian byte order (default: littleEndian)\n");
  157. #endif /* MFCPCM */
  158. #ifdef __STORMC__
  159.     fprintf(stderr,"          -s skip       Only print out every skip'th frame (default: 100)\n");
  160.     fprintf(stderr,"                        (To reduce Contextswitches)                      \n");
  161. #endif
  162.     fprintf(stderr,"\n");
  163. }
  164.  
  165. parse_command now like:
  166.  
  167. static bool parse_command(int argc, char** argv)
  168. {
  169.     int i = 0;
  170.  
  171.     if(argc<3) return false;
  172.  
  173.     while(argv[++i][0]=='-')
  174.         switch(argv[i][1])
  175.         {
  176. #ifndef __STORMC__
  177.             case 'b' : config.mpeg.bitr = atoi(argv[++i]);
  178.                        break;
  179.             case 'c' : config.mpeg.copyright = 1;
  180.                        break;
  181.             case 'o' : config.mpeg.original  = 1;
  182.                        break;
  183. #ifdef MFCPCM
  184.             case 'r' : pcm_switch = 1;
  185.                        break;
  186.             case 'f' : pcm_rate = atoi(argv[++i]);
  187.                        break;
  188.             case 'x' : pcm_byte_order = 1;
  189.                        break;
  190. #endif /* MFCPCM */
  191. #else
  192.             case 'b' : if (i+1<argc) config.mpeg.bitr = atoi(argv[++i]);
  193.                        break;
  194.             case 's' : if (i+1<argc) fskip=atoi(argv[++i]);
  195.             case 'c' : config.mpeg.copyright = 1;
  196.                        break;
  197.             case 'o' : config.mpeg.original  = 1;
  198.                        break;
  199. #ifdef MFCPCM
  200.             case 'r' : pcm_switch = 1;
  201.                        break;
  202.             case 'f' : if (i+1<argc) pcm_rate = atoi(argv[++i]);
  203.                        break;
  204.             case 'x' : pcm_byte_order = 1;
  205.                        break;
  206. #endif /* MFCPCM */
  207. #endif
  208.             case 'h' :
  209.             default  : return false;
  210.        }
  211.  
  212.     if((argc-i)!=2) return false;
  213. #ifndef __STORMC__
  214.     config.infile  = argv[i++];
  215.     config.outfile = argv[i];
  216. #else
  217.     if (i<argc) config.infile  = argv[i++];
  218.     else return false;
  219.     if (i<argc) config.outfile = argv[i];
  220. #endif
  221.     return true;
  222. }
  223.  
  224. portableio.c:
  225. -------------
  226.  
  227. like in bitstream.c ...
  228.  
  229. psy_data.h:
  230. -----------
  231.  
  232. As #warning does not exist in StormC:
  233.  
  234. #ifndef __STORMC__
  235. #warning HURL, this should be different, lazyness....
  236. #endif
  237.  
  238. wave.c:
  239. -------
  240.  
  241. Somehow it could not include some constants... don't know if this is a bug in
  242. the original source or whatever... fixed it by:
  243.  
  244. #ifdef __STORMC__
  245. #define RAW_PCM_LOHI  10
  246. #define RAW_PCM_HILO  11
  247. #endif
  248.  
  249. stat.c:
  250. -------
  251.  
  252. This source file is new. It is only needed in StormC, as stat() is not existing
  253. in StormC. Due to #ifdef, this is an empty File for different compilers :)
  254.  
  255. #ifdef __STORMC__
  256. #include <dos/dos.h>
  257. #include <dos/dosextens.h>
  258. #include <errno.h>
  259. #include <filedefs.h>
  260. #include <clib/exec_protos.h>
  261. #include <time.h>
  262. #include <exec/types.h>
  263. #include <libraries/dos.h>
  264. #include <clib/dos_protos.h>
  265. #include <stdlib.h>
  266. #include <stdio.h>
  267. #include <sys/dir.h>
  268.  
  269. typedef struct FileInfoBlock    FIB;
  270.  
  271. #ifndef UnixToAmigaPath
  272. #define UnixToAmigaPath(path)   path
  273. #endif
  274.  
  275. char* strdup(const char* str)
  276. {
  277.     char* dst = malloc(strlen(str)+1) ;
  278.     if (dst) {
  279.         strcpy(dst, str);
  280.     }
  281.     return dst;
  282. }
  283.  
  284. int stat(const char* name, struct stat* stat)
  285. {
  286.     FileInfoBlock *fib;
  287.     BPTR lock;
  288.     int r = -1;
  289.     struct stat s = {0} ;
  290.  
  291.     *stat = s ;
  292.  
  293.     fib = malloc(sizeof(*fib));
  294.  
  295.     /*
  296.      *  If lock fails find file via its parent directory.  This is for
  297.      *  unix compatibility because you can stat an open write file in unix.
  298.      */
  299.  
  300.     fib->fib_FileName[0] = 0;
  301.  
  302.     if ((lock = Lock((STRPTR)UnixToAmigaPath(name), SHARED_LOCK)) == NULL) {
  303.         extern char* strdup(const char*);
  304.         char *buf = strdup(UnixToAmigaPath(name));
  305.         char *ptr;
  306.         char sk = 0;
  307.  
  308.         for (ptr = buf + strlen(buf); ptr >= buf && *ptr != ':' && *ptr != '/'; --ptr);
  309.         if (ptr < buf || *ptr == ':') {
  310.             ++ptr;
  311.             sk = *ptr;
  312.         }
  313.         *ptr = 0;
  314.         lock = Lock(buf, SHARED_LOCK);
  315.         if (sk)
  316.             *ptr = sk;
  317.         else
  318.             ++ptr;
  319.  
  320.         if (lock == NULL) {
  321.             free(buf);
  322.             errno = ENOENT;
  323.             free(fib);
  324.             return(-1);
  325.         }
  326.         if (Examine(lock, fib)) {
  327.             while (ExNext(lock, fib)) {
  328. #ifdef TEST
  329.                 printf("Compare '%s' '%s'\n", ptr + 1, fib->fib_FileName);
  330. #endif
  331.                 if (stricmp(ptr, fib->fib_FileName) == 0) {
  332.                     r = 0;
  333.                     break;
  334.                 }
  335.             }
  336.         }
  337.         free(buf);
  338.     } else {
  339.         if (Examine(lock, fib))
  340.             r = 0;
  341.     }
  342.     if (lock == NULL) {
  343.         errno = ENOENT;
  344.         free(fib);
  345.         return(-1);
  346.     }
  347.     if (r >= 0) {
  348.         stat->st_size = fib->fib_Size;
  349.         stat->st_ino = (long)((struct FileLock *)BADDR(lock))->fl_Key;
  350.         stat->st_dev = (long)((struct FileLock *)BADDR(lock))->fl_Task;
  351.         stat->st_mode = (fib->fib_DirEntryType > 0) ? S_IFDIR : S_IFREG;
  352.         stat->st_ctime = stat->st_mtime = fib->fib_Date.ds_Days * (1440 * 60) +
  353.                                         fib->fib_Date.ds_Minute * 60 +
  354.                                         fib->fib_Date.ds_Tick / 50 ;
  355.         if ((fib->fib_Protection & 8) == 0)
  356.             stat->st_mode |= S_IREAD;
  357.         if ((fib->fib_Protection & 4) == 0)
  358.             stat->st_mode |= S_IWRITE;
  359.         if ((fib->fib_Protection & 2) == 0)
  360.             stat->st_mode |= S_IEXECUTE;
  361.         if (fib->fib_Protection & 0x40)
  362.             stat->st_mode |= S_IEXECUTE;
  363.     }
  364.     UnLock(lock);
  365.     if (r < 0)
  366.         errno = ENOENT;
  367.     free(fib);
  368.     return(r);
  369. }
  370. #endif
  371.  
  372. Next i used some VERY optimized math-functions i got from Andreas Heumann, which
  373. are done in 100% PPC ASM, replacing some occurences of exp, sqrt, sin, cos, pow
  374. and atan2 by exp_ppc, sqrt_ppc, sin_ppc, cos_ppc, pow_ppc and atan2_ppc, controlled
  375. by a new #define PPCMATH. This gave another 10% speedup :) Now my 18 second
  376. test sample is done in 39 seconds on a 150 MHz machine with -q set to 100.
  377. On a 233 MHz machine it should be done in 25 seconds, which is VERY close to
  378. real-time encoding :)
  379.  
  380. At the end, i created a project file:
  381.  
  382. Additionally to a default PPC-Executable Project file i added:
  383.  
  384. In Preprocessor:
  385.  
  386. BS_FORMAT=BINARY
  387. HUGE_VAL=MAXDOUBLE
  388. __STORMC__=1
  389. MFCPCM=1
  390.  
  391. In Options:
  392.  
  393. Don't use Inline (well, only as i always specified this... does not make sense
  394. i guess... could be left out :) )
  395.  
  396. Indirect Data
  397.  
  398. In Program Start:
  399. Stack: 300 KB
  400.  
  401. (If you start it from the project environment)
  402.  
  403. That is finally all :)
  404.  
  405. Steffen Haeuser
  406. MagicSN@Birdland.es.bawue.de
  407.  
  408.  
  409.  
  410.